$(function(){
    $("#login").click(function(){
        //清空提示信息
        $("#count_span").html("")
        $("#password_span").html("")
        // 	获取请求参数
        var name = $("#count").val().trim();
        var password = $("#password").val().trim();
        //console.log(name,password);
        var ok = true;
        if(name == ''){
            ok = false
            $("#count_span").html("用户名为空")
        }
        if(password == ''){
            ok = false
            $("#password_span").html("密码为空")
        }

        //发送ajax
        if(ok){
            $.ajax({
                url: "http://localhost:80/user/login.do",
                type: "post",
                data:{'name':name,"password":password},
                dataType:'json',
                success:function(result){
                    //console.log(result)
                    if(result.status == 0){
                        var userId = result.data;
                        addCookie("userId",userId,0.5)
                        window.location.href = "edit.html";
                    }if(result.status == 1){
                        $("#count_span").html(result.msg)
                    }if(result.status == 2){
                        $("#password_span").html(result.msg)
                    }

                },
                error:function(){
                    alert("登录失败");
                }

            })
        }



    })
})